/**
 * 消息中心
 * 由 WangYu 创建
 * 日期 2017/10/12
 */
import React, {Component} from 'react';
import {
    StyleSheet,
    Text,
    View,
    Image,
    TouchableOpacity,
    FlatList, TouchableHighlight,
} from 'react-native';
import MyWebView from "../../view/MyWebView";
import NetUtils from "../../util/NetUtils";
import Api from "../../util/Api";
import WFlatList from "../../view/WFlatList";
import MyFlatList from "../../view/MyFlatList";
export default class MessageListPage extends Component {
    constructor(props) {
        super(props);
        this.state = {
            refreshing: false,
            result:null,
        }
    }

    render() {
        return (
            <MyFlatList
                renderItem={this._renderItem}
                refreshing={this.state.refreshing}
                result={this.state.result}
                getData={(pageNow,pageSize)=>this.getMessageList(pageNow,pageSize)}
            />
        )
    }

    _renderItem = ({item, separators}) => {
        return (
            <View style={styles.itemContainer}>
                <View style={styles.titleStyle}>
                    <Text style={{color: 'black', fontSize: 14}}>{item.title}</Text>
                    <Text style={{color: '#999999', fontSize: 12}}>{item.createTime}</Text>
                </View>
                <MyWebView source={{html: item.content}}/>
            </View>);
    };

    getMessageList(pageNow, pageSize) {
        pageNow===1&&this.setState({refreshing: true});
        let params = 'pageNow=' + pageNow + '&pageSize=' +pageSize;
        NetUtils.get(Api.messagelist, params, result => {
            if (result.code === 1) {
                this.setState({result:result.object});
            }
        }, () => {
            this.setState({refreshing: false})
        })
    }

}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#dadada',
    },
    itemContainer: {
        backgroundColor: 'white',
    },
    titleStyle: {
        flexDirection: 'row',
        justifyContent: 'space-between',
        alignItems: 'center',
        borderColor: '#e5e5e5',
        borderBottomWidth: 1,
        height: 50,
        paddingRight: 15,
        paddingLeft: 15
    }
});
